package com.byzk.p2p.admin.system.service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.byzk.p2p.admin.base.util.PageInfo;
import com.byzk.p2p.admin.system.dao.MemberDao;
import com.byzk.p2p.admin.system.dto.MemberLevel;

@Service
public class MemberService {
	
	@Autowired
	private MemberDao memberDao;
	
	public MemberLevel getById(Integer id){
		return memberDao.getById(id);
	}
	
	/**
	 * 遍历所有等级
	 * @return
	 */
	/*public List<MemberLevel> listAll() {
		return memberDao.listAll();
	}*/
	
	public PageInfo<MemberLevel> listAll1(Map<String, Object> queryMap,Integer index,Integer limit) {
		if (index != null && limit != null) {
			if (queryMap == null) {
				queryMap = new HashMap<String, Object>();
			}
			queryMap.put("start", (index-1)*limit);
			queryMap.put("limit", limit);
		}
		Integer total = memberDao.count(queryMap);
		List<MemberLevel> list = memberDao.listAll1(queryMap);
		PageInfo<MemberLevel> pageInfo = new PageInfo<MemberLevel>(total, index, limit);
		pageInfo.setPageList(list);
		return pageInfo;
		
	}
	
	public Integer count(Map<String, Object> queryMap) {
		return memberDao.count(queryMap);
	}
	
	/**
	 * 获取当前等级
	 * @param amount
	 * @return
	 */
	public MemberLevel getLevelByAmount(double amount){
		
		List<MemberLevel> levelList=memberDao.listAll();
		for (int i = 0; i <levelList.size(); i++) {
			Double temp=levelList.get(i).getMin();
			if(amount>=temp){
				return levelList.get(i);
			}else{
				continue;
			}
		}
		return null;
	}

	public List<MemberLevel> listAll() {
		return memberDao.listAll();
	}
	
}
